/**
 * 日期格式化的js
 * 请在主页面引入此js,然后使用dsyDateFormat(传入参数)，获取返回值即可，注意保持此日期时还要进行一遍日期转换否则数据库存储格式依然不正确
 */
function dsyDateFormat(value){	 
	if(value != null && value != '' && typeof(value) != 'undefind'){ 
		if(typeof(value)!="String"){
			value=value.toString();
		}
		if( value.indexOf("-") > 0 ){ 
			var date = getDate(value);
			var year = date.getFullYear();
			var month = "";
			var day = "";
			if(date.getMonth()<9){
				month = "-0"+(date.getMonth()+1);
			}else{
				month = "-"+(date.getMonth()+1);
			}
			if(date.getDate()<10){
				day = "-0"+(date.getDate());
			}else{
				day = "-"+(date.getDate());
			} 
    	    return year+month+day;
    	}
    	else{ 
    		var value1 = format(value, "yyyy-MM-dd");   
    		return value1;
    	}  
	}	
}
function dsyDateFormatByDay(value){	 
	if(value != null && value != '' && typeof(value) != 'undefind'){ 
		if(typeof(value)!="String"){
			value=value.toString();
		}
		if( value.indexOf("-") > 0 ){ 
			var date = getDate(value);
			var year = date.getFullYear();
			var month = "";
			var day = "";
			if(date.getMonth()<9){
				month = "-0"+(date.getMonth()+1);
			}else{
				month = "-"+(date.getMonth()+1);
			}
			if(date.getDate()<10){
				day = "-0"+(date.getDate());
			}else{
				day = "-"+(date.getDate());
			} 
    	    return year+month+day;
    	}
    	else{ 
    		var value1 = format(value, "yyyy-MM-dd HH:mm:ss");  
    		return value1;
    	}  
	}	
}
 function getDate(strDate){
	  var date = eval('new Date(' + strDate.replace(/\d+(?=-[^-]+$)/, 
	   function (a) { return parseInt(a, 10) - 1; }).match(/\d+/g) + ')');
	  return date;
}

var format = function(time, format)
{
	var t = new Date(time);
	var tf = function(i){return (i < 10 ? '0' : '') + i};
	return format.replace(/yyyy|MM|dd|HH|mm|ss/g, function(a){
		switch(a){
			case 'yyyy':
			return tf(t.getFullYear());
			break;
			case 'MM':
			return tf(t.getMonth() + 1);
			break;
			case 'mm':
			return tf(t.getMinutes());
			break;
			case 'dd':
			return tf(t.getDate());
			break;
			case 'HH':
			return tf(t.getHours());
			break;
			case 'ss':
			return tf(t.getSeconds());
		    break;
       }
     })
 }

